# The Long-Term Impact of Mobilization and Repression on Political Trust
# R Code for Replication
# By: Scott Desposato, Gang Wang, Jason Wu
# 
# This version: 22 December 2020
# R version 4.0.2 (2020-06-22)
#
###########################################################################
###                                                                     ###
###                      LOADING PACKAGES AND DATA                      ###
###                                                                     ###
###########################################################################
### Clear Global Environment ###
rm(list=ls())

### Loading Packages ###
library(dbplyr)      # dbplyr_1.4.4
library(MASS)        # MASS_7.3.51.6
library(AER)         # AER_1.2.9

### Loading Data ###
load("DWW_CPS.RData")



###########################################################################
###                                                                     ###
###                 APPENDIX AND SUPPLEMENTARY ANALYSIS                 ###
###                                                                     ###
###########################################################################

###########################################################################
##  Table A.1: First Stage Polynomial Models for Fuzzy RDD               ##
###########################################################################
# 1988 - 1989 #
tempdata <- subset(x=data, year_88_89 == 1)
ivmodel1 <- ivreg(T ~ D + X_c + X2 + X3 + DX + DX2 + DX3, data = tempdata)
summary(ivmodel1)

# 1987 - 1990 #
tempdata <- subset(x=data, year_87_90 == 1)
ivmodel2 <- ivreg(T ~ D + X_c + X2 + X3 + DX + DX2 + DX3, data = tempdata)
summary(ivmodel2)

# 1986 - 1991 #
tempdata <- subset(x=data, year_86_91 == 1)
ivmodel3 <- ivreg(T ~ D + X_c + X2 + X3 + DX + DX2 + DX3, data = tempdata)
summary(ivmodel3)

# 1985 - 1992 #
tempdata <- subset(x=data, year_85_92 == 1)
ivmodel4 <- ivreg(T ~ D + X_c + X2 + X3 + DX + DX2 + DX3, data = tempdata)
summary(ivmodel4)

# 1984 - 1993 #
tempdata <- subset(x=data, year_84_93 == 1)
ivmodel5 <- ivreg(T ~ D + X_c + X2 + X3 + DX + DX2 + DX3, data = tempdata)
summary(ivmodel5)

# 1984 - 1994 #
tempdata <- subset(x=data, year_84_94 == 1)
ivmodel6 <- ivreg(T ~ D + X_c + X2 + X3 + DX + DX2 + DX3, data = tempdata)
summary(ivmodel6)



###########################################################################
##  Table A.2: Complete Results from Models of Trust in                  ##
##  Central Government                                                   ##
###########################################################################
## Model 1: Ordinarly Least Squares (OLS) ##
M1 <- lm(TrustCent ~ T, data = data)
summary(M1)

## Model 2: Ordinarly Least Squares (OLS) Model 2 ##
M2 <- lm(TrustCent ~ T + Education + CCP + GovtJob + Income2 + marriage, data = data)
summary(M2)

## Model 3: Baseline Fuzzy RDD ##
M3 <- ivreg(TrustCent ~ T |D+X_c, data = data)
summary(M3)

## Model 4: Fuzzy RDD with Covariates ##
M4 <- ivreg(TrustCent ~ T + Education + CCP + GovtJob + Income2 + marriage
            |D+X_c + Education + CCP + GovtJob + Income2 + marriage, data = data)
summary(M4)

## Model 5: Complete Baseline Fuzzy RDD ##
M5 <- ivreg(TrustCent ~ T |D+X_c+X2+X3+DX+DX2+DX3, data = data)
summary(M5)

## Model 6: Complete Fuzzy RDD with Covariates ##
M6 <- ivreg(TrustCent ~ T + Education + CCP + GovtJob + Income2 + marriage
            |D+X_c+X2+X3+DX+DX2+DX3 + Education + CCP + GovtJob + Income2 + marriage, data = data)
summary(M6)



###########################################################################
##  Table A.3: Complete Results from Models of Trust in                  ##
##  Provincial Government                                                ##
###########################################################################
## Model 1: Ordinarly Least Squares (OLS) ##
M1 <- lm(TrustProv ~ T, data = data)
summary(M1)

## Model 2: Ordinarly Least Squares (OLS) ##
M2 <- lm(TrustProv ~ T + Education + CCP + GovtJob + Income2 + marriage, data = data)
summary(M2)

## Model 3: Baseline Fuzzy RDD ##
M3 <- ivreg(TrustProv ~ T |D+X_c, data = data)
summary(M3)

## Model 4: Fuzzy RDD with Covariates ##
M4 <- ivreg(TrustProv ~ T + Education + CCP + GovtJob + Income2 + marriage
            |D+X_c + Education + CCP + GovtJob + Income2 + marriage, data = data)
summary(M4)

## Model 5: Complete Baseline Fuzzy RDD ##
M5 <- ivreg(TrustProv ~ T |D+X_c+X2+X3+DX+DX2+DX3, data = data)
summary(M5)

## Model 6: Complete Fuzzy RDD with Covariates ##
M6 <- ivreg(TrustProv ~ T + Education + CCP + GovtJob + Income2 + marriage
            |D+X_c+X2+X3+DX+DX2+DX3 + Education + CCP + GovtJob + Income2 + marriage, data = data)
summary(M6)



###########################################################################
##  Table A.4: Complete Results from Models of Trust in                  ##
##  Local Government                                                     ##
###########################################################################
## Model 1: Ordinarly Least Squares (OLS) ##
M1 <- lm(TrustLocal ~ T, data = data)
summary(M1)

## Model 2: Ordinarly Least Squares (OLS) ##
M2 <- lm(TrustLocal ~ T + Education + CCP + GovtJob + Income2 + marriage, data = data)
summary(M2)

## Model 3: Baseline Fuzzy RDD ##
M3 <- ivreg(TrustLocal ~ T |D+X_c, data = data)
summary(M3)

## Model 4: Fuzzy RDD with Covariates ##
M4 <- ivreg(TrustLocal ~ T + Education + CCP + GovtJob + Income2 + marriage
            |D+X_c + Education + CCP + GovtJob + Income2 + marriage, data = data)
summary(M4)

## Model 5: Complete Baseline Fuzzy RDD ##
M5 <- ivreg(TrustLocal ~ T |D+X_c+X2+X3+DX+DX2+DX3, data = data)
summary(M5)

## Model 6: Complete Fuzzy RDD with Covariates ##
M6 <- ivreg(TrustLocal ~ T + Education + CCP + GovtJob + Income2 + marriage
            |D+X_c+X2+X3+DX+DX2+DX3 + Education + CCP + GovtJob + Income2 + marriage, data = data)
summary(M6)



###########################################################################
##  Table A.5: Trust in Central Government is Not Higher for Students    ##
##  Subject to Expanded Military Training                                ##
###########################################################################
### Subsetting The Data To Those Not Exposed to Tiananmen and Experienced
### Expanded Military Training
temp <- subset(data,is.na(T) == 0 & T == 0 & start_year > 1988 & start_year < 1993)

### Difference-of-Means T-Test
ttest <- t.test(TrustCent ~ Peking, data = temp)
ttest

### Trust Difference 
ttest$estimate[2]-ttest$estimate[1]

### Standard Deviation (SD) 
by(temp$TrustCent, INDICES = temp$Peking, FUN = sd)

### Standard Error (se)
ttest$stderr

### N 
# Peking = 1
sum(is.na(temp[temp$Peking==1,"TrustCent"])==0)
# Peking = 0
sum(is.na(temp[temp$Peking==0,"TrustCent"])==0)



###########################################################################
##  Table A.6: Trust in Central Government Is Not Higher for Peking      ##
##  Students Subject to Required Military Training                       ##
###########################################################################
### Subsetting The Data To Those Not Exposed to Tiananmen, went to Peking
### University
temp <- subset(data,is.na(T) == 0 & T == 0 & Peking == 1)
## Coding those with No military based on their enrollment year
temp$NoMilTraining <- temp$start_year < 1989 | temp$start_year > 1992


### Difference-of-Means T-Test
ttest <- t.test(TrustCent ~ NoMilTraining, data = temp)
ttest

### Trust Difference 
ttest$estimate[2]-ttest$estimate[1]

### Standard Deviation (SD) 
by(temp$TrustCent, INDICES = temp$NoMilTraining, FUN = sd)

### Standard Error (se)
ttest$stderr

### N 
# Fall '89-'92
sum(is.na(temp[temp$NoMilTraining==0,"TrustCent"])==0)
# Fall '93+
sum(is.na(temp[temp$NoMilTraining==1,"TrustCent"])==0)



###########################################################################
##  Table A.7: Even When Excluding Students Who Attended a Mandatory     ##
##  Year of Military Training, Trust in Central Government is            ##
##  Significantly Lower for the Tiananmen Cohort                         ##
###########################################################################
### Subsetting the Data to only exclude students who attended mandatory
### military training. 
temp <- subset(data,is.na(T)==0 & (Peking==0 | (start_year < 1989 | start_year > 1992)))

### Central Government
## Model 1: Ordinarly Least Squares (OLS) ##
M1 <- lm(TrustCent ~ T, data = temp)
M1$coefficients[2]

## Model 2: Ordinarly Least Squares (OLS) ##
M2 <- lm(TrustCent ~ T + Education + CCP + GovtJob + Income2 + marriage, data = temp)
M2$coefficients[2]

## Model 3: Baseline Fuzzy RDD ##
M3 <- ivreg(TrustCent ~ T |D+X_c, data = temp)
M3$coefficients[2]

## Model 4: Fuzzy RDD with Covariates ##
M4 <- ivreg(TrustCent ~ T + Education + CCP + GovtJob + Income2 + marriage
            |D+X_c + Education + CCP + GovtJob + Income2 + marriage, data = temp)
M4$coefficients[2]

## Model 5: Complete Baseline Fuzzy RDD ##
M5 <- ivreg(TrustCent ~ T |D+X_c+X2+X3+DX+DX2+DX3, data = temp)
M5$coefficients[2]

## Model 6: Complete Fuzzy RDD with Covariates ##
M6 <- ivreg(TrustCent ~ T + Education + CCP + GovtJob + Income2 + marriage
            |D+X_c+X2+X3+DX+DX2+DX3 + Education + CCP + GovtJob + Income2 + marriage, data = temp)
M6$coefficients[2]

### Provincial Government
## Model 1: Ordinarly Least Squares (OLS) ##
M1 <- lm(TrustProv ~ T, data = temp)
M1$coefficients[2]

## Model 2: Ordinarly Least Squares (OLS) ##
M2 <- lm(TrustProv ~ T + Education + CCP + GovtJob + Income2 + marriage, data = temp)
M2$coefficients[2]

## Model 3: Baseline Fuzzy RDD ##
M3 <- ivreg(TrustProv ~ T |D+X_c, data = temp)
M3$coefficients[2]

## Model 4: Fuzzy RDD with Covariates ##
M4 <- ivreg(TrustProv ~ T + Education + CCP + GovtJob + Income2 + marriage
            |D+X_c + Education + CCP + GovtJob + Income2 + marriage, data = temp)
M4$coefficients[2]

## Model 5: Complete Baseline Fuzzy RDD ##
M5 <- ivreg(TrustProv ~ T |D+X_c+X2+X3+DX+DX2+DX3, data = temp)
M5$coefficients[2]

## Model 6: Complete Fuzzy RDD with Covariates ##
M6 <- ivreg(TrustProv ~ T + Education + CCP + GovtJob + Income2 + marriage
            |D+X_c+X2+X3+DX+DX2+DX3 + Education + CCP + GovtJob + Income2 + marriage, data = temp)
M6$coefficients[2]

### Local Government
## Model 1: Ordinarly Least Squares (OLS) ##
M1 <- lm(TrustLocal ~ T, data = temp)
M1$coefficients[2]

## Model 2: Ordinarly Least Squares (OLS) ##
M2 <- lm(TrustLocal ~ T + Education + CCP + GovtJob + Income2 + marriage, data = temp)
M2$coefficients[2]

## Model 3: Baseline Fuzzy RDD ##
M3 <- ivreg(TrustLocal ~ T |D+X_c, data = temp)
M3$coefficients[2]

## Model 4: Fuzzy RDD with Covariates ##
M4 <- ivreg(TrustLocal ~ T + Education + CCP + GovtJob + Income2 + marriage
            |D+X_c + Education + CCP + GovtJob + Income2 + marriage, data = temp)
M4$coefficients[2]

## Model 5: Complete Baseline Fuzzy RDD ##
M5 <- ivreg(TrustLocal ~ T |D+X_c+X2+X3+DX+DX2+DX3, data = temp)
M5$coefficients[2]

## Model 6: Complete Fuzzy RDD with Covariates ##
M6 <- ivreg(TrustLocal ~ T + Education + CCP + GovtJob + Income2 + marriage
            |D+X_c+X2+X3+DX+DX2+DX3 + Education + CCP + GovtJob + Income2 + marriage, data = temp)
M6$coefficients[2]



###########################################################################
##  Table A.8: Full Models of Trust in Central Government, Excluding     ##
##  Students from Peking University with One Year of Mandatory Military  ##
##  Training                                                             ##
###########################################################################
### Subsetting the Data to only exclude students who attended mandatory
### military training. 
temp <- subset(data,is.na(T)==0 & (Peking==0 | (start_year < 1989 | start_year > 1992)))

## Model 1: Ordinarly Least Squares (OLS) ##
M1 <- lm(TrustCent ~ T, data = temp)
summary(M1)

## Model 2: Ordinarly Least Squares (OLS) Model 2 ##
M2 <- lm(TrustCent ~ T + Education + CCP + GovtJob + Income2 + marriage, data = temp)
summary(M2)

## Model 3: Baseline Fuzzy RDD ##
M3 <- ivreg(TrustCent ~ T |D+X_c, data = temp)
summary(M3)

## Model 4: Fuzzy RDD with Covariates ##
M4 <- ivreg(TrustCent ~ T + Education + CCP + GovtJob + Income2 + marriage
            |D+X_c + Education + CCP + GovtJob + Income2 + marriage, data = temp)
summary(M4)

## Model 5: Complete Baseline Fuzzy RDD ##
M5 <- ivreg(TrustCent ~ T |D+X_c+X2+X3+DX+DX2+DX3, data = temp)
summary(M5)

## Model 6: Complete Fuzzy RDD with Covariates ##
M6 <- ivreg(TrustCent ~ T + Education + CCP + GovtJob + Income2 + marriage
            |D+X_c+X2+X3+DX+DX2+DX3 + Education + CCP + GovtJob + Income2 + marriage, data = temp)
summary(M6)



###########################################################################
##  Table A.9: Full Models of Trust in Provincial Government, Excluding  ##
##  Students from Peking University with One Year of Mandatory Military  ##
##  Training                                                             ##
###########################################################################
### Subsetting the Data to only exclude students who attended mandatory
### military training. 
temp <- subset(data,is.na(T)==0 & (Peking==0 | (start_year < 1989 | start_year > 1992)))

## Model 1: Ordinarly Least Squares (OLS) ##
M1 <- lm(TrustProv ~ T, data = temp)
summary(M1)

## Model 2: Ordinarly Least Squares (OLS) ##
M2 <- lm(TrustProv ~ T + Education + CCP + GovtJob + Income2 + marriage, data = temp)
summary(M2)

## Model 3: Baseline Fuzzy RDD ##
M3 <- ivreg(TrustProv ~ T |D+X_c, data = temp)
summary(M3)

## Model 4: Fuzzy RDD with Covariates ##
M4 <- ivreg(TrustProv ~ T + Education + CCP + GovtJob + Income2 + marriage
            |D+X_c + Education + CCP + GovtJob + Income2 + marriage, data = temp)
summary(M4)

## Model 5: Complete Baseline Fuzzy RDD ##
M5 <- ivreg(TrustProv ~ T |D+X_c+X2+X3+DX+DX2+DX3, data = temp)
summary(M5)

## Model 6: Complete Fuzzy RDD with Covariates ##
M6 <- ivreg(TrustProv ~ T + Education + CCP + GovtJob + Income2 + marriage
            |D+X_c+X2+X3+DX+DX2+DX3 + Education + CCP + GovtJob + Income2 + marriage, data = temp)
summary(M6)



###########################################################################
##  Table A.10: Full Models of Trust in Local Government, Excluding      ##
##  Students from Peking University with One Year of Mandatory Military  ##
##  Training                                                             ##
###########################################################################
### Subsetting the Data to only exclude students who attended mandatory
### military training. 
temp <- subset(data,is.na(T)==0 & (Peking==0 | (start_year < 1989 | start_year > 1992)))

## Model 1: Ordinarly Least Squares (OLS) ##
M1 <- lm(TrustLocal ~ T, data = temp)
summary(M1)

## Model 2: Ordinarly Least Squares (OLS) ##
M2 <- lm(TrustLocal ~ T + Education + CCP + GovtJob + Income2 + marriage, data = temp)
summary(M2)

## Model 3: Baseline Fuzzy RDD ##
M3 <- ivreg(TrustLocal ~ T |D+X_c, data = temp)
summary(M3)

## Model 4: Fuzzy RDD with Covariates ##
M4 <- ivreg(TrustLocal ~ T + Education + CCP + GovtJob + Income2 + marriage
            |D+X_c + Education + CCP + GovtJob + Income2 + marriage, data = temp)
summary(M4)

## Model 5: Complete Baseline Fuzzy RDD ##
M5 <- ivreg(TrustLocal ~ T |D+X_c+X2+X3+DX+DX2+DX3, data = temp)
summary(M5)

## Model 6: Complete Fuzzy RDD with Covariates ##
M6 <- ivreg(TrustLocal ~ T + Education + CCP + GovtJob + Income2 + marriage
            |D+X_c+X2+X3+DX+DX2+DX3 + Education + CCP + GovtJob + Income2 + marriage, data = temp)
summary(M6)



###########################################################################
##  Table A.11: Placebo Test: OLS Models of Attitudes Toward China's     ##
##  Regional Influence Show No Evidence that Tiananmen Affects These     ##
##  Attitudes                                                            ##
###########################################################################
### Cohort Years Included: 1988-89
## Subsetting Data
temp <- subset(data, year_88_89 == 1)
## OLS Model
M1 <- lm(V7B ~ T + Education + CCP + GovtJob + Income2 + marriage, data = temp)
summary(M1)

### Cohort Years Included: 1987-90
## Subsetting Data
temp <- subset(data, year_87_90 == 1)
## OLS Model
M2 <- lm(V7B ~ T + Education + CCP + GovtJob + Income2 + marriage, data = temp)
summary(M2)

### Cohort Years Included: 1986-91
## Subsetting Data
temp <- subset(data, year_86_91 == 1)
## OLS Model
M3 <- lm(V7B ~ T + Education + CCP + GovtJob + Income2 + marriage, data = temp)
summary(M3)

### Cohort Years Included: 1985-92
## Subsetting Data
temp <- subset(data, year_85_92 == 1)
## OLS Model
M4 <- lm(V7B ~ T + Education + CCP + GovtJob + Income2 + marriage, data = temp)
summary(M4)

### Cohort Years Included: 1984-93
## Subsetting Data
temp <- subset(data, year_84_93 == 1)
## OLS Model
M5 <- lm(V7B ~ T + Education + CCP + GovtJob + Income2 + marriage, data = temp)
summary(M5)



###########################################################################
##  Table A.12: Placebo Test: No Evidence that Exposure to Tiananmen     ## 
##  Affects Attitudes Attitudes Towards China's Regional Influence       ##
###########################################################################
## Model 1: Ordinarly Least Squares (OLS) ##
M1 <- lm(V7B ~ T, data = data)
summary(M1)

## Model 2: Ordinarly Least Squares (OLS) ##
M2 <- lm(V7B ~ T  + Education + CCP + GovtJob + Income2 + marriage , data = data)
summary(M2)

## Model 3: Baseline Fuzzy RDD ##
M3 <- ivreg(V7B ~ T |D+X_c, data = data)
summary(M3)

## Model 4: Fuzzy RDD with Covariates ##
M4 <- ivreg(V7B ~ T + Education + CCP + GovtJob + Income2 + marriage 
            |D+X_c + Education + CCP + GovtJob + Income2 + marriage ,
            data = data)
summary(M4)

## Model 5: Complete Baseline Fuzzy RDD ##
M5 <- ivreg(V7B ~ T |D+X_c+X2+X3+DX+DX2+DX3, data = data)
summary(M5)

###
## Model 6: Complete Fuzzy RDD with Covariates ##
M6 <- ivreg(V7B ~ T +  Education + CCP + GovtJob + Income2 + marriage 
           |D+X_c+X2+X3+DX+DX2+DX3 + Education + CCP + GovtJob + Income2 + marriage, 
            data = data)
summary(M6)
